import { Vec3, ChunkPosition } from '@/core/types';

export class MathUtils {
  static vec3Add(a: Vec3, b: Vec3): Vec3 {
    return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
  }

  static vec3Subtract(a: Vec3, b: Vec3): Vec3 {
    return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
  }

  static vec3Distance(a: Vec3, b: Vec3): number {
    const diff = this.vec3Subtract(a, b);
    return Math.sqrt(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z);
  }

  static worldToChunk(worldPos: Vec3): ChunkPosition {
    return {
      x: Math.floor(worldPos.x / 16),
      z: Math.floor(worldPos.z / 16)
    };
  }

  static chunkToWorld(chunkPos: ChunkPosition): Vec3 {
    return {
      x: chunkPos.x * 16,
      y: 0,
      z: chunkPos.z * 16
    };
  }

  static clamp(value: number, min: number, max: number): number {
    return Math.max(min, Math.min(max, value));
  }
}